package com.ys.service.hr.impl;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.ys.enume.base.TransactionTypeEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSON;
import com.ys.dto.AddDto;
import com.ys.entity.base.TbFileInfo;
import com.ys.entity.business.ThrCanvassApplyItem;
import com.ys.entity.flow.YspModel;
import com.ys.entity.hr.ThrOperateCompanyApply;
import com.ys.entity.hr.ThrOperateCompanyBeian;
import com.ys.entity.hr.ThrOperateCompanyRoute;
import com.ys.entity.sys.TsUserChange;
import com.ys.entity.sys.YsCol;
import com.ys.entity.sys.YsMenu;
import com.ys.entity.sys.YsProcInst;
import com.ys.enume.flow.FlowEnum;
import com.ys.enume.flow.YsProcInstEnum;
import com.ys.mapper.business.DiySqlMapper;
import com.ys.mapper.business.ThrCanvassApplyItemMapper;
import com.ys.mapper.finance.TcwAccountCountForCompanyMapper;
import com.ys.mapper.hr.HrMapper;
import com.ys.mapper.hr.ThrOperateCompanyBeianMapper;
import com.ys.mapper.hr.ThrOperateCompanyRouteMapper;
import com.ys.service.business.TbFileInfoService;
import com.ys.service.business.TcwAccountDetailedForCompanyService;
import com.ys.service.finance.TcwOperateCompanyPrepaymentService;
import com.ys.service.flow.YspTaskService;
import com.ys.service.hr.ThrOperateCompanyApplyService;
import com.ys.service.hr.ThrOperateCompanyBeianService;
import com.ys.util.BidUtil;
import com.ys.util.CheckUtil;
import com.ys.util.DateUtil;
import com.ys.util.SnowflakeIdWorker;
import com.ys.util.shiro.ShiroUtils;
import com.ys.vo.Flow;
import com.ys.vo.R;

@Service("thrOperateCompanyBeianService")
public class ThrOperateCompanyBeianServiceImpl implements ThrOperateCompanyBeianService {
	private static final Logger logger = LoggerFactory.getLogger(ThrOperateCompanyBeianServiceImpl.class);

	@Autowired
	private HrMapper hrMapper;
	@Autowired
	private ThrOperateCompanyBeianMapper thrOperateCompanyBeianMapper;
	@Autowired
	private TcwAccountCountForCompanyMapper tcwAccountCountForCompanyMapper;
	@Autowired
	private YspTaskService yspTaskService;
	@Autowired
	private CheckUtil checkUtil;
	@Autowired
	private ThrOperateCompanyApplyService thrOperateCompanyApplyService;
	@Autowired
	private TbFileInfoService tbFileInfoService;
	@Autowired
	private TcwAccountDetailedForCompanyService tcwAccountDetailedForCompanyService;
	@Autowired
	private DiySqlMapper diySqlMapper;
	@Autowired
	private ThrOperateCompanyRouteMapper thrOperateCompanyRouteMapper;

	@Autowired
	private ThrCanvassApplyItemMapper thrCanvassApplyItemMapper;

	@Autowired
	private TcwOperateCompanyPrepaymentService tcwOperateCompanyPrepaymentService;


	@Override
	@Transactional
	public R add(Map<String, Object> params, Long menuId) throws Exception {
		logger.info("运营公司备案新增传参:"+params);
		//参数验证
		String errorBack = checkParams(params, menuId);
		if(errorBack!=null && !"".equals(errorBack)){
			return R.error(errorBack);
		}
		ThrOperateCompanyBeian entity = JSON.parseObject(JSON.toJSONString(params), ThrOperateCompanyBeian.class);
		// 获取运营公司编码
		String code = "";
		ThrOperateCompanyApply entityMax = new ThrOperateCompanyApply().setOrderby("A.Vgsbm desc").queryFirst();
		if (entityMax == null) {
			return R.error( "运营公司不存在");
		} else if (!entityMax.getVgsbm().startsWith("GS")) {
			return R.error( "系统中存在不符合运营公司编码的数据");
		}
		code = "GS" + BidUtil.parseIntToFourLen(Integer.parseInt(entityMax.getVgsbm().replace("GS", "")) + 1);
		entity.setCode(code);

		if(params.get("operatorUserId")!=null && !"".equals(params.get("operatorUserId"))){
			//根据运营人工号获取运营人变更id
			TsUserChange tsUserChangeByOpe = new TsUserChange().setUserId(params.get("operatorUserId").toString()).setOrderby("A.Id DESC").queryFirst();
			if(tsUserChangeByOpe!=null){
				entity.setOperatorChangeId(tsUserChangeByOpe.getId());
			}else{
				return R.error( "运营人工号信息有误！");
			}
		}
		TsUserChange tsUserChange = new TsUserChange().setUserId(ShiroUtils.getUserId()).setOrderby("A.CreateTime DESC").queryFirst();
		if(tsUserChange!=null){
			entity.setCreateChangeId(tsUserChange.getId());//制单人变更信息
		}else {
			R.error("未查询到制单人信息！");
		}


		thrOperateCompanyBeianMapper.insert(entity);
		//如果是调取招商信息，则需要同步更新招商信息表的附件
		if(entity.getCanvassApplyItemId()!=null && !"".equals(entity.getCanvassApplyItemId())){
			saveFiles(entity);
		}
		String bid = entity.getBid();
		YsMenu ysMenu = new YsMenu().setId(menuId).queryFirst();
		if (ysMenu.getFlowModelId().longValue() != 0L) {
			YspModel yspModel = new YspModel().setId(ysMenu.getFlowModelId()).queryFirst();
			String codeModel = yspModel.getCode();
			String createUserId = ShiroUtils.getUserId();
			yspTaskService.init(codeModel, bid, createUserId);
		}
		if(entity.getCanvassApplyItemId()!=null && !"".equals(entity.getCanvassApplyItemId())){
			return R.ok(AddDto.gotoEdit("/web/hr/thrOperateCompanyBeian/toEditByCanvassApply?bid=" + entity.getBid()));
		}else{
			return R.ok(AddDto.gotoEdit("/web/hr/thrOperateCompanyBeian/toEdit?bid=" + entity.getBid()));
		}

	}

	//如果是调取招商信息，则需要同步更新招商信息表的附件
	public void saveFiles(ThrOperateCompanyBeian entity)throws Exception{
		//先删除附件信息
		diySqlMapper.delTbFileInfoBySourceTypeAndSourceId(14,entity.getId());
		diySqlMapper.delTbFileInfoBySourceTypeAndSourceId(15,entity.getId());
		List<TbFileInfo> tbFileInfoList = new TbFileInfo().setSourceId(entity.getCanvassApplyItemId()).where("A.SourceType IN (22,23)").queryList();
		if(tbFileInfoList!=null && tbFileInfoList.size()>0){
			//营业执照附件
			List<TbFileInfo> tbFileInfoByGraduation = tbFileInfoList.stream().filter(item->item.getSourceCode().equals("businesslicense")).collect(Collectors.toList());
			if(tbFileInfoByGraduation.size()>0){
				for(TbFileInfo item:tbFileInfoByGraduation){
					item.setSourceId(entity.getId());
					item.setSourceType(14);
					tbFileInfoService.add(item);
				}
			}
			//合作协议附件
			List<TbFileInfo> tbFileInfoByEducation = tbFileInfoList.stream().filter(item->item.getSourceCode().equals("cooperateAgreement")).collect(Collectors.toList());
			if(tbFileInfoByEducation.size()>0){
				for(TbFileInfo item:tbFileInfoByEducation){
					item.setSourceId(entity.getId());
					item.setSourceType(15);
					tbFileInfoService.add(item);
				}
			}
		}
	}
	
	@Override
	@Transactional
	public R edit(Map<String, Object> params, Long menuId) throws Exception {
		logger.info("运营公司备案编辑传参:"+params);
		//参数验证
		String errorBack = checkParams(params, menuId);
		if(errorBack!=null && !"".equals(errorBack)){
			return R.error(errorBack);
		}
		ThrOperateCompanyBeian entity = JSON.parseObject(JSON.toJSONString(params), ThrOperateCompanyBeian.class);

		//根据运营人工号获取运营人变更id
		TsUserChange tsUserChange = new TsUserChange().setUserId(params.get("operatorUserId").toString()).setOrderby("A.Id DESC").queryFirst();
		if(tsUserChange!=null){
			entity.setOperatorChangeId(tsUserChange.getId());
		}else{
			return R.error( "运营人工号信息有误！");
		}

		// 验证状态
		YsProcInst ysProcInst = new YsProcInst().setBid(entity.getBid()).queryFirst();
		if (ysProcInst == null) {
			return R.error("审批数据不存在，无法编辑");
		} else if (ysProcInst.getStateFlow() != YsProcInstEnum.StateFlow.INIT.value) {
			return R.error("已流转，无法编辑");
		}
		//如果是调取招商信息，则需要同步更新招商信息表的附件
		if(entity.getCanvassApplyItemId()!=null && !"".equals(entity.getCanvassApplyItemId())){
			saveFiles(entity);
		}
		thrOperateCompanyBeianMapper.update(entity);
		return R.ok(AddDto.noAction());
	}

	/**
	 * 删除
	 */
	@Override
	public R deleteTrue(Long id) throws Exception {
		if (id == null) {
			return R.error("ID不能为空");
		}
		ThrOperateCompanyBeian entity = new ThrOperateCompanyBeian().setId(id).queryFirst();
		if (entity.getEffectStock() == FlowEnum.EffectStock.EFFECTED.value) {
			return R.error("已生效数据无法删除");
		}
		thrOperateCompanyBeianMapper.deleteTrue(id);
		String loginUserId = ShiroUtils.getUserId();
		yspTaskService.flowDelete(entity.getBid(), loginUserId);
		return R.ok();
	}

	/**
	 * 流转通过
	 */
	@Override
	@Transactional
	public R flowPass(Long id, String loginUserId) throws Exception {

		ThrOperateCompanyBeian entity = new ThrOperateCompanyBeian().setId(id).queryFirst();
		Flow f = yspTaskService.flowPass(entity.getBid(), loginUserId);
		if (f.getCode() == Flow.Code.FAILED.value) {
			return R.error(f.getMsg());
		} else {
			if (f.getState() == Flow.State.FINISH.value) {
				flowFinish(entity.getBid());
			}
			return R.ok();
		}
	}


	/**
	 * 流转结束
	 */
	@Override
	@Transactional
	public void flowFinish(String bid) throws Exception {

		ThrOperateCompanyBeian entity = new ThrOperateCompanyBeian().setBid(bid).queryFirst();
		YsProcInst ysProcInst = new YsProcInst().setBid(bid).queryFirst();
		if (ysProcInst.getStateFlow() != YsProcInstEnum.StateFlow.FINISH.value) {
			return;
		}
		entity.setEffectStock(FlowEnum.EffectStock.EFFECTED.value);
		Date date = new Date();
		entity.setUpdateTime(date);
		thrOperateCompanyBeianMapper.update(entity);

		//添加运营公司管理表
		Map<String, Object> paramsByCompanyApply = new HashMap<>();
		paramsByCompanyApply.put("vgsmc",entity.getFullName());//公司名称
		paramsByCompanyApply.put("vgsjc",entity.getName());//公司简称
		paramsByCompanyApply.put("vgsbm",entity.getCode());//公司编码
		paramsByCompanyApply.put("vgsFr",entity.getCorporation());//公司法人
		paramsByCompanyApply.put("vgsFrId",entity.getCorporationIdCard());//法人身份证
		paramsByCompanyApply.put("vgsSh",entity.getTaxNo());//公司税号
		paramsByCompanyApply.put("ratioStatus",1);//是否绩效管理(0是、1否)
		paramsByCompanyApply.put("gfJe",0);//已收培训费
		paramsByCompanyApply.put("gledfJe",0);//培训费额度
		paramsByCompanyApply.put("operateOrgId",entity.getOperateOrgId());//所属运营机构ID
		paramsByCompanyApply.put("operatorChangeId",entity.getOperatorChangeId());//运营人用户变动ID
		TsUserChange tsUserChange = new TsUserChange().setId(entity.getOperatorChangeId()).queryFirst();
		if(tsUserChange!=null)paramsByCompanyApply.put("cuser",tsUserChange.getUserId());//运营人工号
		paramsByCompanyApply.put("operationsAttribute",entity.getOperationsAttribute());//运营属性(1公司账户、2运营账户、3过渡账户、4直营账户)
		paramsByCompanyApply.put("operationsStatus",entity.getOperationsStatus());//运营状态(1预备、2正常、3冻结、4停用)
		paramsByCompanyApply.put("corporationPhone",entity.getCorporationPhone());//法人联系方式
		paramsByCompanyApply.put("startPerformance",entity.getStartPerformance());//初始绩效
		paramsByCompanyApply.put("specialPerformance",entity.getSpecialPerformance());//特殊绩效
		paramsByCompanyApply.put("trainingFees",entity.getTrainingFees());//培训费标准
		paramsByCompanyApply.put("remark",entity.getRemark());//备注说明
		paramsByCompanyApply.put("businesslicense",entity.getBusinesslicense());//营业执照
		paramsByCompanyApply.put("cooperateAgreement",entity.getCooperateAgreement());//合作协议
		paramsByCompanyApply.put("otherFile",entity.getOtherFile());//其他附件
		paramsByCompanyApply.put("manageRatio",entity.getManageRatio());//管理比例
		paramsByCompanyApply.put("status",1);
		//if(entity.getCanvassApplyItemId()!=null)paramsByCompanyApply.put("operateOrgId",entity.getCanvassApplyItemId());//招商申请表子表id


		ThrOperateCompanyApply thrOperateCompanyApply = thrOperateCompanyApplyService.add(paramsByCompanyApply);

		//**********兼容1.0的字段**********
		SnowflakeIdWorker idWorker = new SnowflakeIdWorker(0, 0);
		long guid1 = idWorker.nextId();
		paramsByCompanyApply.put("guid",guid1);
		paramsByCompanyApply.put("pid",1);
		paramsByCompanyApply.put("pGuid","ee9cc071-4b07-4bc2-b060-9d5dfc9981b3");
		paramsByCompanyApply.put("lid",guid1);
		paramsByCompanyApply.put("nid",guid1);
		paramsByCompanyApply.put("bid",entity.getBid());
		paramsByCompanyApply.put("vGsMcP","福建省逸思信息科技有限公司");
		paramsByCompanyApply.put("vGsJcP","逸思科技");
		paramsByCompanyApply.put("vGsBmP","GS0001");
		paramsByCompanyApply.put("vGsJbP","");
		paramsByCompanyApply.put("deleted",0);
		paramsByCompanyApply.put("id",thrOperateCompanyApply.getId());
		paramsByCompanyApply.put("activeFlow","FlowZD");
		hrMapper.updateThrOperateCompanyApplyByOld(paramsByCompanyApply);
		//**********兼容1.0的字段**********



		int businesslicenseSourceType = 17;
		int cooperateAgreementSourceType = 18;
		int otherFileSourceType = 19;
		//更新附件表信息
		List<TbFileInfo> tbFileInfoList = new TbFileInfo().setSourceId(entity.getId()).where("A.SourceType IN (14,15,16)").queryList();
		if(tbFileInfoList!=null && tbFileInfoList.size()>0){
			//营业执照
			List<TbFileInfo> tbFileInfoByGraduation = tbFileInfoList.stream().filter(item->item.getSourceCode().equals("businesslicense")).collect(Collectors.toList());
			if(tbFileInfoByGraduation.size()>0){
				for(TbFileInfo item:tbFileInfoByGraduation){
					item.setSourceId(thrOperateCompanyApply.getId());
					item.setSourceType(businesslicenseSourceType);
					tbFileInfoService.add(item);
				}
			}
			//合作协议
			List<TbFileInfo> tbFileInfoByEducation = tbFileInfoList.stream().filter(item->item.getSourceCode().equals("cooperateAgreement")).collect(Collectors.toList());
			if(tbFileInfoByEducation.size()>0){
				for(TbFileInfo item:tbFileInfoByEducation){
					item.setSourceId(thrOperateCompanyApply.getId());
					item.setSourceType(cooperateAgreementSourceType);
					tbFileInfoService.add(item);
				}
			}
			//其他附件
			List<TbFileInfo> tbFileInfoByOtherFile = tbFileInfoList.stream().filter(item->item.getSourceCode().equals("otherFile")).collect(Collectors.toList());
			if(tbFileInfoByOtherFile.size()>0){
				for(TbFileInfo item:tbFileInfoByOtherFile){
					item.setSourceId(thrOperateCompanyApply.getId());
					item.setSourceType(otherFileSourceType);
					tbFileInfoService.add(item);
				}
			}
		}
		ThrCanvassApplyItem thrCanvassApplyItem = null;
		BigDecimal fJe = BigDecimal.ZERO;
		BigDecimal costStandard = null;
		String tnvestTypeStr = "";
		//如果是调取招商信息申请表，扣除资金，并且修改运营公司编码信息
		if(entity.getCanvassApplyItemId()!=null){
			//获取招商信息申请表信息
			thrCanvassApplyItem = new ThrCanvassApplyItem().setId(entity.getCanvassApplyItemId()).queryFirst();
			//扣除公司初始资金
			costStandard = new BigDecimal(thrCanvassApplyItem.getCostStandard());
			fJe= fJe.subtract(costStandard);
			//获取招商类型对应值
			if(thrCanvassApplyItem.getInvestType()==0){
				tnvestTypeStr = "首店";
			}else if(thrCanvassApplyItem.getInvestType()==1){
				tnvestTypeStr = "次店";
			}else {
				tnvestTypeStr = "特殊店";
			}
			//修改招商信息表的运营公司编码
			thrCanvassApplyItem.setVgsbm(entity.getCode());
			thrCanvassApplyItemMapper.update(thrCanvassApplyItem);
		}

		/*
		//添加公司实时资金表
		TcwAccountCountForCompany tcwAccountCountForCompany = null;
		{
			String guid = entity.getCode();
			String vGsBm = entity.getCode();
			String vGsMc = entity.getFullName();
			String vGsJc = entity.getName();
			Integer bDeleted = 0;
			BigDecimal fFzEd = BigDecimal.ZERO;
			BigDecimal fDjJe = BigDecimal.ZERO;
			String vZhLx = "";
			if(entity.getOperationsAttribute()==1){
				vZhLx = "公司账户";
			}else if(entity.getOperationsAttribute()==2){
				vZhLx = "运营账户";
			}else if(entity.getOperationsAttribute()==3){
				vZhLx = "过渡账户";
			}else {
				vZhLx = "直营账户";
			}
			tcwAccountCountForCompany = TcwAccountCountForCompany.tcwAccountCountForCompany(guid, vGsBm, vGsMc, vGsJc, BigDecimal.ZERO, bDeleted, fFzEd, fDjJe, vZhLx, 1);
			tcwAccountCountForCompanyMapper.insert(tcwAccountCountForCompany);
		}
		 */

		//如果是调取招商信息申请表，则添加流水表
		if(entity.getCanvassApplyItemId()!=null){
			//添加流水

			//划出流水,划出至客服部,备注单号，公司编码，公司简称，招商类型
			tcwAccountDetailedForCompanyService.addTcwAccountDetailedForCompanyNoTrigger(
					entity.getCode(), "GS0614",  TransactionTypeEnum.BusinessType.THR_OperateCompanyBeian.name, fJe,
					date, date,
					"运营公司备案:" + entity.getBid() + "，公司编码:" + entity.getCode()+ "，公司简称:" + entity.getName()
							+ "，招商类型:" + tnvestTypeStr,
					 entity.getBid(),  null);
			//划入流水
			tcwAccountDetailedForCompanyService.addTcwAccountDetailedForCompanyNoTrigger(
					"GS0614", entity.getCode(), TransactionTypeEnum.BusinessType.THR_OperateCompanyBeian.name, costStandard,
					date, date,
					"运营公司备案:" + entity.getBid() + "，公司编码:" + entity.getCode()+ "，公司简称:" + entity.getName()
							+ "，招商类型:" + tnvestTypeStr,
					 entity.getBid(),  null);
		}


		//  添加公司路径，兼容1.0
		ThrOperateCompanyRoute thrOperateCompanyRoute = null;
		{
			String guid = guid1 + "";

			String vGsMcP = "福建省逸思信息科技有限公司";
			String vGsJcP = "逸思科技";
			String vGsBmP = "GS0001";
			String vGsJbP = "";
			String vGsMc = entity.getFullName();
			String vGsJc = entity.getName();
			String vGsBm = entity.getCode();
			String vGsJb = null;

			// 循环获取公司路径名称
			String routeName = "逸思科技" + "→" +"逸思科技" + "→" + entity.getName();
			String routeCode = "C101" + "." +"GS0001" + "." + entity.getCode();

			String cUser = tsUserChange.getUserId();
			String cUserName = tsUserChange.getUserName();

			String cDeptRouteCode = null;
			String cDeptRouteName = null;
			BigDecimal vJcBl = new BigDecimal(85);
			BigDecimal vYyBl = new BigDecimal(85);
			BigDecimal vTsBl = new BigDecimal(85);
			Date cdTime = null;
			thrOperateCompanyRoute = ThrOperateCompanyRoute.thrOperateCompanyRoute(guid, vGsMcP, vGsJcP, vGsBmP, vGsJbP, vGsMc, vGsJc, vGsBm, vGsJb, routeName, routeCode, cUser, cUserName, cDeptRouteCode, cDeptRouteName, vJcBl, vYyBl, vTsBl, cdTime, "", 1);
			thrOperateCompanyRouteMapper.insert(thrOperateCompanyRoute);
		}
	}


	/**
	 * 参数验证
	 */
	@Override
	@Transactional
	public String checkParams(Map<String, Object> params, Long menuId) throws Exception {
		//获取pc字段数据
		List<YsCol> listField = new YsCol()
				.where("A.MenuId = "+menuId)
				.setOrderby("A.SortNo ASC")
				.queryList();
		//验证必填字段的非空；其他字段的长度限制、类型
		String backMsg = checkUtil.checkTableColLengthAndDataType(
				"THR_OperateCompanyBeian",
				listField,
				params,
				ysColItem->ysColItem.getFormEditRequired()!=null && ysColItem.getFormEditRequired() == 1 && !ysColItem.getCode().equals("code")
		);
		if(params.get("corporationPhone")!=null && !"".equals(params.get("corporationPhone")) && !checkUtil.isPhone(params.get("corporationPhone").toString())){
			backMsg = "法人联系方式手机号格式有误！";
		}
		if(params.get("corporationIdCard")!=null && !"".equals(params.get("corporationIdCard")) && !checkUtil.isIDNumberValid(params.get("corporationIdCard").toString())){
			backMsg = "法人身份证号格式有误！";
		}
		if(params.get("specialPerformance")!=null && !"".equals(params.get("specialPerformance"))){
			BigDecimal specialPerformance = new BigDecimal(params.get("specialPerformance").toString());
			if(specialPerformance.compareTo(new BigDecimal(15))>0){
				backMsg = "特殊运营绩效不能大于15%！";
			}
		}
		//验证运营公司简称是否重复
		if(params.get("name")!=null){
			ThrOperateCompanyBeian thrOperateCompanyBeian = new ThrOperateCompanyBeian()
					.setName(params.get("name").toString());
			//若是修改时
			if(params.get("id")!=null && !"".equals(params.get("id"))){
				thrOperateCompanyBeian.where("A.code != '"+params.get("code")+"'");
			}
			int isSame = thrOperateCompanyBeian.count();
			if(isSame>0){
				backMsg = "运营公司简称重复！";
			}
		}

		return backMsg;
	}


	//获取列表数据
	@Override
	@Transactional
	public Map<String,Object> getExtraParam( String bid) throws Exception{
		Map<String,Object> entity = new ThrOperateCompanyBeian()

				.addLeftJoin("TS_UserChange B on B.Id = A.OperatorChangeId")
				.addField("B.UserId operatorUserId")//运营人工号
				.addField("B.UserName operatorUserName")//运营人
				.addField("B.RoleName roleName")//运营人岗位
				.addField("B.DeptName deptName")//运营人部门

				.addLeftJoin("TS_OperateOrg O on O.Id = A.OperateOrgId")
				.addLeftJoin("TS_OperateOrg PO on PO.Id = O.Pid AND 1=1")
				.addField("O.Name orgName")//机构名称
				.addField("O.Pid orgbm")//上级公司编码
				.addField("PO.Name orgJc")//上级公司简称

				.addLeftJoin("THR_CanvassApplyItem C on C.Id = A.CanvassApplyItemId AND 1=1")
				.addField("C.Pbid pbid")//招商信息申请单号
				.addField("C.InvestType investType")//招商类型
				.addField("C.CostStandard costStandard")//费用标准

				.setBid(bid)
				.queryFirstMap();
		return entity;
	}
}
